package com.d2rv.guide;

import com.d2rv.model.GoalModel;
import com.d2rv.offscreen.OffScreen3D;
import processing.core.PVector;

/**
 * This class extends Goal and displays a unique direction to follow.
 *
 * @author Darrieutort A., Dupouy A., Rossignol L., Van Poucke A.
 */
public class GoalDestination extends Goal {

    private PVector position;

    /**
     * Default constructor.
     *
     * @param model reference of the goal model
     */
    public GoalDestination(GoalModel model) {
        super(model);
        this.position = null;
    }

    /**
     * Initializes the position of the goal to null.
     */
    public void init() {
        this.position = null;
    }

    /**
     * Updates the position of the goal and its model position.
     *
     * @param position the new position of the goal
     */
    public void position(PVector position) {
        this.position = position;
        this.goalmodel().position(position);
    }

    /**
     * Returns the position of the goal.
     *
     * @return the position of the goal
     */
    public PVector position() {
        return this.position;
    }

    /**
     * Draws the goal model.
     *
     * @param parent the current offscreen
     */
    public void draw(OffScreen3D parent) {
        if (this.position != null) {
            parent.pushMatrix();
            parent.translate(this.position().x, this.position().y - 50, this.position().z);
            this.model.draw(parent);
            parent.popMatrix();
        }
    }

    /**
     * Draws the goal model on the guide offscreen
     *
     * @param parent the current offscreen
     * @param userpos the user position
     */
    public void drawGuide(OffScreen3D parent, PVector userpos) {
        if (this.position != null) {
            parent.pushMatrix();
            parent.translate(this.position().x, this.position().y, this.position().z);
            this.model.draw(parent);
            parent.popMatrix();
        }
    }

    /**
     * Validates the goal by setting the position to null.
     */
    public void goalAchieved() {
        this.position = null;
    }
}